package com.ruyuan.scholartrade.controller;

import com.scholar.shop.common.CommonRes;
import com.scholar.shop.trad.order.api.OrderAPI;
import com.scholar.shop.trad.order.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单相关SDK
 *
 * @author Snow create in 2018/5/28
 * @version v2.0
 * @since v7.0.0
 */
@CrossOrigin
@RestController
@RequestMapping("/trade/order/open/api")
public class OrderAPIController  {
  @Autowired
  private OrderAPI orderAPI ;

    @GetMapping("/getModel/{orderSn}")
    public CommonRes<OrderDetailVO> getModel(@PathVariable String orderSn) {


        return this.orderAPI.getModel(orderSn) ;
    }

    /**
     * 读取一个订单详细<br/>
     *
     * @param orderSn 订单编号 必传
     * @return
     */
    @GetMapping("/getOrderVO/{orderSn}")
    public CommonRes<OrderDetailVO> getOrderVO(@PathVariable String orderSn) {
        return this.orderAPI.getOrderVO(orderSn) ;
    }

    @PostMapping("/updateOrderCommentStatus")
    public CommonRes<Boolean> updateOrderCommentStatus(@RequestParam String orderSn, @RequestParam String commentStatus) {
        return this.orderAPI.updateOrderCommentStatus(orderSn,commentStatus) ;
    }


    @GetMapping("/getOrderByTradeSn/{tradeSn}")
    public CommonRes<List<OrderDetailVO>> getOrderByTradeSn(@PathVariable String tradeSn) {
        return this.orderAPI.getOrderByTradeSn(tradeSn) ;
    }



    @PostMapping("/payOrder")
    public CommonRes<Boolean> payOrder(String sn, Double price, String returnTradeNo, String permission) {
       return this.orderAPI.payOrder(sn,price,returnTradeNo,permission) ;
    }



    @GetMapping("/getOrderNumByMemberID/{memberId}")
    public CommonRes<Integer> getOrderNumByMemberID(@PathVariable Integer memberId) {
       return this.orderAPI.getOrderNumByMemberID(memberId) ;
    }


    @GetMapping("/getOrderCommentNumByMemberID")
    public CommonRes<Integer> getOrderCommentNumByMemberID(@RequestParam Integer memberId, @RequestParam String commentStatus) {
        return this.orderAPI.getOrderNumByMemberID(memberId) ;
    }

    @PostMapping("/updateOrderStatus")
    public CommonRes<Boolean> updateOrderStatus(@RequestParam String sn, @RequestParam String orderStatus) {

        return this.orderAPI.updateOrderStatus(sn,orderStatus) ;
    }

    @GetMapping("/getOrderStatusNum")
    public CommonRes<OrderStatusNumVO> getOrderStatusNum(@RequestParam Integer memberId, @RequestParam Integer sellerId) {

        return this.orderAPI.getOrderStatusNum(memberId, sellerId);
    }

    
    @PostMapping("/updateTradeStatus")
    public CommonRes<Boolean> updateTradeStatus(@RequestParam String sn, @RequestParam String orderStatus) {
       this.orderAPI.updateTradeStatus(sn, orderStatus);
        return CommonRes.success(true) ;
    }

    @PostMapping("/addOrderItemRefundPrice")
    public CommonRes<Boolean> addOrderItemRefundPrice(@RequestBody OrderDTO order) {
        return this.orderAPI.addOrderItemRefundPrice(order) ;
    }

    
    @PostMapping("/updateItemsCommentStatus")
    public CommonRes<Boolean> updateItemsCommentStatus(@RequestParam String orderSn,@RequestParam Integer goodsId, @RequestParam String commentStatus) {
        return this.orderAPI.updateItemsCommentStatus(orderSn, goodsId, commentStatus);
    }

    @GetMapping("/orderItems")
    public CommonRes<List<OrderItemsVO>> orderItems(@RequestParam String orderSn) {
        return orderAPI.orderItems(orderSn) ;
    }

    
    @GetMapping("/getOrder/{orderSn}")
    public CommonRes<OrderVO> getOrder(@PathVariable String orderSn) {
        return this.orderAPI.getOrder(orderSn) ;
    }

    
    @PostMapping("/ship")
    public CommonRes<Boolean> ship(@RequestBody DeliveryVO deliveryVO, @RequestParam String permission) {
     return   this.orderAPI.ship(deliveryVO,permission) ;
    }
    @GetMapping("/getItemsPromotionTypeandNum")
    
    public CommonRes<List<Map>> getItemsPromotionTypeandNum(@RequestParam String  orderSn) {
        return this.orderAPI.getItemsPromotionTypeandNum(orderSn) ;
    }

}
